let info_box = $(".info");

// 获取商品id
let regExp = new RegExp(/id=\d/);
let goods_id = regExp.exec(location.href)[0][3];

// 根据id获取信息
let options = {
  url: `http://localhost:3000/goods_list?id=${goods_id}`,
};

p_ajax(options)
  .then((res) => {
    let item = JSON.parse(res)[0];
    let info_list = {
        "价格": item.price,
        "品牌": item.brand,
        "型号": item.model,
        "容量": item.storage.capacity+"GB",
        "尺寸":item.display.size+"英寸",
        "分辨率":item.display.resolution+"像素"
    }
    // let key_list = ["价格", "品牌", "型号", "容量", "尺寸", "分辨率"];
    // let value_list = [
    //   item.price,
    //   item.brand,
    //   item.model,
    // //   item.storage.capacity + "GB",
    // //   item.display.size + "英寸",
    // //   item.display.resolution + "像素",
    // ];
    Object.keys(info_list).forEach((key)=>{
        console.log(key+"："+info_list[key]); 
        info_box.append(`<span>${key}：${info_list[key]}</span>`);
    })
  })
  .catch(() => {});
